var enableComment = function () {
    
    $(".comment").submit(
        function(){
            console.log('send comment');
            sendComment($('#commentText').val());
            $('#commentText').val("");
            $('#commentText').text("");
         return;   
        }
    );
}
var sendComment = function (string) {
    var jObj = new Object();
    jObj.id = eventID;
    jObj.comment = string;
    jObj.user = userID;
      //var jobj = {"id":eventID,"comment":string,"user":userID};
     httpPost('comment',jObj,getCommentsResponse);
     console.log('sendCommnet to servlet');
     var commentString =  "<div  id = 'comment"+commentNum+"'>"
               +"<img class = 'commentimg' src = "+user.picture.data.url+">"
               +"<a href='https://www.facebook.com/"+userID+"'class='commentname'>"+user.name+"</a>"
               +"<p class='commentcontent'>"+string+"</p>"
               +"<hr/></div>"
               
     if(commentNum==0)
     {
         $("#commentfield").append(commentString);
     }
     else
     {
         $("#comment"+(commentNum-1)).after(commentString);
       
     }
     commentNum++;
}
var getCommentsResponse = function (response)
{
    console.log('send Comment get response');
}
var getfriendlist = function()
{
    FB.api(
    "/me/friendlists",
    function (response) {
      if (response && !response.error) {
        /* handle the result */
       console.log('get friend suc');
        for(var i =0;i<response.length;i++)
        {
            invitefriends(eventID,response[i].id);
        }
      }
    }
);
}
var invitefriends = function(id,user)
{
    FB.api(
        "/"+id+"/invite"+user,
        'POST',
        function(response)
        {
            if(response&&!response.error)
            {
                console.log('invitefriend suc');
            }
        }
    );
}
